package com.zut.blocks.service.grade.vo;

import com.zut.blocks.base.domain.CourseGrade;
import com.zut.blocks.base.domain.User;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;
import java.util.Map;

@Data
@NoArgsConstructor
public class FinalGrade {
    private Integer id;
    private String userNumber;
    private String gender;
    private String name;
    private Double finalGrade;

    public FinalGrade(User user, List<CourseGrade> courseGrade, Map<Integer, Integer> gradeMap) {
        this.id = user.getId();
        this.userNumber = user.getUserNumber();
        this.gender = user.getGender();
        this.name = user.getName();

        Double finalGrade = 0D;
        for (CourseGrade grade : courseGrade) {
            finalGrade += (gradeMap.getOrDefault(grade.getId(), 0) * 1.0 / grade.getTotalGrade()) * 100.0 * (grade.getGradePercent() / 100.0);
        }
        this.finalGrade = (double) (Math.round(finalGrade * 100) / 100);
    }
}
